{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import caffe"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "arr = np.zeros((3, 2, 2))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[[ 103.939,  103.939],\n",
       "        [ 103.939,  103.939]],\n",
       "\n",
       "       [[ 116.779,  116.779],\n",
       "        [ 116.779,  116.779]],\n",
       "\n",
       "       [[ 123.68 ,  123.68 ],\n",
       "        [ 123.68 ,  123.68 ]]])"
      ]
     },
     "execution_count": 34,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "arr[0,:,] = 103.939\n",
    "arr[1,:,] = 116.779\n",
    "arr[2,:,] = 123.68\n",
    "arr"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "blob = caffe.proto.caffe_pb2.BlobProto()\n",
    "blob.channels, blob.height, blob.width = arr.shape\n",
    "blob.data.extend(arr.astype(float).flat)\n",
    "binaryproto_file = open('vgg_mean.binaryproto', 'wb' )\n",
    "binaryproto_file.write(blob.SerializeToString())\n",
    "binaryproto_file.close()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "arr2 = np.zeros((2, 2, 3))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 75,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[[ 0.  0.  0.]\n",
      "  [ 0.  0.  0.]]\n",
      "\n",
      " [[ 1.  1.  1.]\n",
      "  [ 1.  1.  1.]]]\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "3.0"
      ]
     },
     "execution_count": 75,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "arr2[0,:] = 0\n",
    "arr2[1,:] = 1\n",
    "print(arr2)\n",
    "\n",
    "arr2[:,:,0] = 1\n",
    "arr2[:,:,1] = 2\n",
    "arr2[:,:,2] = 3\n",
    "arr2[0][1][2]"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 2",
   "language": "python",
   "name": "python2"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
